package com.flower.oss.advice;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.stereotype.Service;

import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * @author lavender
 * @version 1.0
 * @date 2024-12-22 22:39
 */
@Service
@Slf4j
public class HelloService implements BeanNameAware, BeanFactoryAware {

    private BeanFactory beanFactory;

    private String beanName;

    @SneakyThrows
    public String sayHello(String name) {
        Object bean = beanFactory.getBean(beanName);
        log.info("bean name:{},bean:{}", beanName, bean);
        TimeUnit.SECONDS.sleep(new Random().nextInt(3));

        return "hello" + name;
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        this.beanFactory = beanFactory;
    }

    @Override
    public void setBeanName(String s) {

        this.beanName = s;
    }
}
